package com.cloud.system.controller;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.cloud.common.domain.Result;
import com.cloud.controller.BaseController;
import com.cloud.enums.BusinessType;
import com.cloud.common.enums.ProjectStatus;
import com.cloud.logs.Logs;
import com.cloud.security.aop.RequestPermissions;
import com.cloud.system.entity.ProjectAnnex;
import com.cloud.system.service.ISysProjectAnnexService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 系统附件
 *
 * @author yzj
 * @since 2022-11-30
 */
@Tag(name = "系统附件")
@RestController
@RequestMapping("/system/projectAnnex")
public class SysProjectAnnexController extends BaseController {

    @Autowired
    private ISysProjectAnnexService sysProjectAnnexService;

    @Operation(summary = "系统附件分页")
    @RequestPermissions("system:projectAnnex:list")
    @GetMapping("/list")
    public Result list(ProjectAnnex projectAnnex) {
        startPage();
        List<ProjectAnnex> list = sysProjectAnnexService.selectSysProjectAnnexList(projectAnnex);
        return getDataTable(list);
    }

    @Operation(summary = "新增系统附件信息")
    @Logs(title = "新增系统附件", businessType = BusinessType.INSERT)
    @RequestPermissions("system:projectAnnex:add")
    @PostMapping("/insert")
    public Result insert(@RequestBody ProjectAnnex projectAnnex) {
        return toResult(sysProjectAnnexService.insertObject(projectAnnex));
    }

    @Operation(summary = "修改系统附件信息")
    @Logs(title = "修改系统附件", businessType = BusinessType.UPDATE)
    @RequestPermissions("system:projectAnnex:edit")
    @PostMapping("/update")
    public Result update(@RequestBody ProjectAnnex projectAnnex) {
        return toResult(sysProjectAnnexService.updateObject(projectAnnex));
    }

    @Operation(summary = "查询系统附件详情")
    @RequestPermissions("system:projectAnnex:query")
    @GetMapping("/getInfo")
    public Result getInfo(Long id) {
        return Result.success("查询成功", sysProjectAnnexService.selectAnnexInfo(id));
    }

    @Operation(summary = "删除系统附件信息")
    @Logs(title = "删除系统附件", businessType = BusinessType.DELETE)
    @RequestPermissions("system:projectAnnex:remove")
    @PostMapping("/remove")
    public Result remove(String ids) {
        List<String> list = Arrays.asList(ids.split(StringPool.COMMA));
        return toResult(sysProjectAnnexService.removeByIds(list));
    }

    @Operation(summary = "根据应用状态查询配置列表")
    @GetMapping("/getApplyAnnexList")
    public Result getApplyAnnexList() {
        List<ProjectAnnex> projectAnnexList = sysProjectAnnexService.selectApplyProjectAnnex(ProjectStatus.APPLIED.getCode());
        return Result.success("查询成功", projectAnnexList);
    }

}
